package com.hardson.toolkit.swing.datepicker;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;

public class TransparentButton extends JButton{

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	boolean fillRec;
	public TransparentButton(final String text,final boolean fillRec){
		super(text);
		this.fillRec=fillRec;
		this.setBorder(null);
		this.addMouseListener(new MouseAdapter(){
			@Override
			public void mouseEntered(final MouseEvent e) {
				TransparentButton.this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
				TransparentButton.this.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED));
				TransparentButton.this.repaint();
			}
	    @Override
		public void mouseExited(final MouseEvent e) {
	    	TransparentButton.this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
	    	TransparentButton.this.setBorder(null);
				TransparentButton.this.repaint();
	    }
		});
	}
	@Override
	public void paint(final Graphics g){
//      super.paint(g);
		Color bg=this.getBackground();
		Color fg=this.getForeground();
		if(this.fillRec){
			g.setColor(bg);
			g.fillRect(0,0,this.getWidth(),this.getHeight());
		}
		g.setColor(fg);
		Insets insets=this.getMargin();
		g.drawString(this.getText(),insets.left,insets.top);
		super.paintBorder(g);
  }
	public void setFillRec(final boolean fillRec){
		this.fillRec=fillRec;
	}
//	public void setBackground(Color color){
//		super.setBackground(color);
//		super.repaint();
//	}
}
